createRandom
Generate a random mnemonic (total number 12) and using TRON path "m/44'/195'" by default, return the 0th account address and private key.
Usage
TronWeb.createRandom();
Parameters
Parameter | Description | Data Type |
---|---|---|
options | Optional parameter with three fields: { path: 'BIP44 path', extraEntropy: 'entropy', locale: 'the locale' } | Object |
Returns
Object - Returns randomly created account information, including mnemonic, public key, and private key. If the entered BIP44 path does not start with m/44'/195', throw an exception - Error: Invalid tron path provided.
Example
Get a mnemonic and the 0th account:
> TronWeb.createRandom();
> {
'mnemonic': {
'phrase': 'chimney cloth deny claim play rude love dose apart shove rack stone',
'path': "m/44'/195'/0'/0/0",
'locale': 'en'
},
'privateKey': '0x79092289f3bfde55f079202e3642b2c4ba071d5f0b85d65b1919c8724e94848c',
'publicKey':
'0x0421c47d627bc2d856760dda17b42b726b4bc8f5def76aed0cbcd71566d0ffedfc3904c9c854854a5019b8373d2aed0c6b96ff5f3be07722403088742b0949a6c9',
'address': 'TEFAyPnainfiAJBuhExfMLJeHHxD2DZJmF'
};
If you want to get an account with the custom path index, you can provide the path.
> TronWeb.createRandom({path: "m/44'/195'/1'/0/0"});
> {
"mnemonic": {
"phrase": "mixture load skull render can lamp off primary hill right first question",
"path": "m/44'/195'/1'/0/0",
"locale": "en"
},
"privateKey": "0xd53b52088c7baf60b2c9c83a51bc543df59a8f5b209d6f8c6b65908dfb338bbd",
"publicKey": "0x046e81fd824046b3b03d90e4249c14ffedcb40210743c52ba68e2e3b62250c9370b449e88966acb28bde3ab751afa119c91186d5bd9a250f9b43e32486108b72a7",
"address": "THwRMnsVjeXfC4sbvLpFknTEjaNisvYnQy"
}